package chapter01

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object SparkWoldCountV1 {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()//.setMaster("local").setAppName("SparkWoldCount")
    val sc = new SparkContext(conf)



    val rdd: RDD[String] =
      sc.textFile(args(0))

    rdd.flatMap(_.split(","))
      .map((_,1))
      .reduceByKey(_+_)
      .map(x=>(x._2,x._1))
      .sortByKey(false)
      .map(x=>(x._1,x._2))
      .saveAsTextFile(args(1))

    sc.stop()
  }

}
